//
//  HMessageManageCell.m
//  BXlive
//
//  Created by k on 2018/4/17.
//  Copyright © 2018年 cat. All rights reserved.
//

#import "HMessageManageCell.h"
#import <SLDeveloperTools/SLDeveloperTools.h>
#import <Masonry/Masonry.h>
#import <SDAutoLayout/SDAutoLayout.h>

@implementation HMessageManageCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self createUI];
    }
    return self;
}

- (void)createUI{
    
    self.titleLabel = [UILabel initWithFrame:CGRectZero size:14 color:sl_textColors alignment:NSTextAlignmentLeft lines:1];
    self.titleLabel.font = SLBFont(__ScaleWidth(15));
    [self.contentView addSubview:self.titleLabel];
    self.manageSwitch = [[UIButton alloc]initWithFrame:CGRectZero];
    [self.manageSwitch setBackgroundImage:CImage(@"setting_switch_on") forState:BtnSelected];
    [self.manageSwitch setBackgroundImage:CImage(@"setting_switch_off") forState:BtnNormal];
    [self.manageSwitch addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventTouchDown];
    [self.contentView addSubview:self.manageSwitch];
    
    self.titleLabel.sd_layout.leftSpaceToView(self.contentView,__ScaleWidth(12)).topSpaceToView(self.contentView,__ScaleWidth(20)).bottomSpaceToView(self.contentView,__ScaleWidth(20)).widthIs(__ScaleWidth(220));
    self.manageSwitch.sd_layout.rightSpaceToView(self.contentView, __ScaleWidth(15)).topSpaceToView(self.contentView, __ScaleWidth(20)).widthIs(__ScaleWidth(49)).heightIs(__ScaleWidth(22));
}
+ (instancetype)cellWithTabelView:(UITableView *)tableView {
    static NSString *cellIdentifier = @"HMessageManageCell";
    HMessageManageCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[HMessageManageCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    return cell;
}

- (void)switchAction:(UIButton *)sender {
    
    sender.selected = !sender.selected;
    
    if (self.messageManageDelegate && [self.messageManageDelegate respondsToSelector:@selector(switchClick:cell:)]) {
        [self.messageManageDelegate switchClick:sender cell:self];
    }
}

@end
